﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for clsGIAOVIEN
/// </summary>
public class clsGIAOVIEN
{
	public clsGIAOVIEN()
	{
		//
		// TODO: Add constructor logic here
		//
    }

    #region Select Giao Vien
    public DataTable Select()
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        try
        {
            dt = connect.GetSelectCommand("GIAOVIEN_Select", null);
        }
        catch
        {
            dt = null;
        }
        return dt;
    }
    #endregion

    #region Insert Giáo Viên
    public string Insert(string magv, string hotengv, string chuyennganh, string diachi, string dienthoai, string macn, string email)
    {
        DatabaseConnect connect = new DatabaseConnect();

        // Tham so
        SqlParameter[] para = new SqlParameter[7];
        para[0] = new SqlParameter("@magv", magv);
        para[1] = new SqlParameter("@hotengv", hotengv);
        para[2] = new SqlParameter("@machuyennganh", chuyennganh);
        para[3] = new SqlParameter("@diachi", diachi);
        para[4] = new SqlParameter("@dienthoai", dienthoai);
        para[5] = new SqlParameter("@macn", macn);
        para[6] = new SqlParameter("@email", email);

        try {
            connect.ExecuteQuery("GIAOVIEN_Insert", para);
            return "OK";
        }
        catch {
            return "ERR";
        }
    }
    #endregion

    #region Update Giáo Viên
    public string Update(string magv, string hotengv, string chuyennganh, string diachi, string dienthoai, bool danghi, string macn, string email)
    {
        DatabaseConnect connect = new DatabaseConnect();

        // Tham so
        SqlParameter[] para = new SqlParameter[8];
        para[0] = new SqlParameter("@magv", magv);
        para[1] = new SqlParameter("@hotengv", hotengv);
        para[2] = new SqlParameter("@machuyennganh", chuyennganh);
        para[3] = new SqlParameter("@diachi", diachi);
        para[4] = new SqlParameter("@dienthoai", dienthoai);
        para[5] = new SqlParameter("@danghi", danghi);
        para[6] = new SqlParameter("@macn", macn);
        para[7] = new SqlParameter("@email", email);

        try {
            connect.ExecuteQuery("GIAOVIEN_Update", para);
            return "OK";
        }
        catch {
            return "ERR";
        }
    }
    public string Update_changekey(string magv, string hotengv, string chuyennganh, string diachi, string dienthoai, bool danghi, string macn, string email,string magvnew)
    {
        DatabaseConnect connect = new DatabaseConnect();

        // Tham so
        SqlParameter[] para = new SqlParameter[9];
        para[0] = new SqlParameter("@magv", magv);
        para[1] = new SqlParameter("@hotengv", hotengv);
        para[2] = new SqlParameter("@machuyennganh", chuyennganh);
        para[3] = new SqlParameter("@diachi", diachi);
        para[4] = new SqlParameter("@dienthoai", dienthoai);
        para[5] = new SqlParameter("@danghi", danghi);
        para[6] = new SqlParameter("@macn", macn);
        para[7] = new SqlParameter("@email", email);
        para[8] = new SqlParameter("@magvnew", magvnew);

        try
        {
            connect.ExecuteQuery("GIAOVIEN_Update_changekey", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    #endregion

    #region Delete Giáo Viên
    public string Delete(string magv)
    {
        DatabaseConnect connect = new DatabaseConnect();

        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@magv", magv);

        try
        {
            connect.ExecuteQuery("GIAOVIEN_Delete", para);
            return "OK";
        }
        catch {
            return "ERR";
        }
    }
    #endregion

}